<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>
        手机号: <input type="text" id="tel"> <button id="yanzheng">获取验证码<button>
    </p>
    <script>
        const tel = document.getElementById('tel');
        const btn = document.getElementById('yanzheng');

        let timer;
        btn.onclick = function () {
            let num = 10;
            if (/^\d{11}$/.test(tel.value)) {
                clearInterval(timer);
                timer = setInterval(function () {
                    num--;
                    btn.innerHTML = num + 's后重发';
                    btn.setAttribute('disabled', true);
                    if (num < 0) {
                        clearInterval(timer);
                        btn.innerHTML = '点击重新获取';
                        btn.removeAttribute('disabled');
                    }
                }, 1000)
            } else {
                alert('手机号输入错误')
            }
        }

    </script>
</body>

<html>